#include "basic_head.h"
#ifndef __CLIENT__
#define __CLIENT__

// 日志
/* #define NETDISK_LOG_INFO(netfd, clientAddr)                                                                                                       \
    {                                                                                                                                             \
        syslog(LOG_INFO, "1 client connected, fd = %d, ip = %s, port = %hu\n", netfd, inet_ntoa(clientAddr.sin_addr), ntohs(clientAddr.sin_port)); \
    } */
/* #define NETDISK_LOG_ERR(ret, err, msg)                                                            \
    {                                                                                             \
        if (ret == err)                                                                           \
        {                                                                                         \
            syslog(LOG_ERR, "an error occurred in %s:%s:%d\n", __FILE__, __FUNCTION__, __LINE__); \
            syslog(LOG_ERR, msg);                                                                 \
        }                                                                                         \
    } */
#define NETDISK_LOG_INFO_1(fd, msg, clientAddr)                                                                                        \
    {                                                                                                                                  \
        openlog("client", LOG_PID, LOG_LOCAL0);                                                                           \
        syslog(LOG_INFO, "msg: %s, fd: %d, ip: %s, port: %hu\n", msg, fd, inet_ntoa(clientAddr.sin_addr), ntohs(clientAddr.sin_port)); \
        closelog();                                                                                                                    \
    }

#define NETDISK_LOG_INFO_2(fd, msg, username)                                   \
    {                                                                           \
        openlog("client", LOG_PID, LOG_LOCAL0);                    \
        syslog(LOG_INFO, "username: %s, fd: %d, msg: %s\n", username, fd, msg); \
        closelog();                                                             \
    }

#define NETDISK_LOG_ERR(msg)                                                        \
    {                                                                                         \
        openlog("client", LOG_PID, LOG_LOCAL0);                                  \
        syslog(LOG_ERR, "an error occurred in %s:%s:%d\n", __FILE__, __FUNCTION__, __LINE__); \
        syslog(LOG_ERR, "msg = %s\n", msg);                                                   \
        closelog();                                                                           \
    }

#define BIG_FILE 100 * 1024 * 1024

// 用于在socket网络通信中传输数据的结构体
typedef struct train_s
{
    int length;
    char data[1024];
} train_t;

typedef struct shareRes_s
{
    char order[1024];
    char path[1024];
    char token[1024];
    char username[1024];
    struct sockaddr_in serverAddr;
} shareRes_t;

// getparameter.c
int getparameter(char *key, char *value); // 动态加载配置文件config.ini中的的内容

// user.c
int user_login(int socket_fd, char *username);    // 用户登录
int user_register(int socket_fd, char *username); // 用户注册

// handle.c
int handle(char *buf, int socket_fd, char *username, char *token, struct sockaddr_in *pserverAddr); // 处理用户输入的指令

// long_cmd.c
void *upload(void *arg);   // puts
void *download(void *arg); // gets

// transmit.c
int recvn(int socket_fd, void *buf, int length); // 接收来自服务器的数据
int send_str(int socket_fd, void *buf);          // 发送数据给服务器
int send_file(int socket_fd, int file_fd);       // 发送文件给服务器
int recv_file(int socket_fd, int file_fd);       // 接收来自服务器的文件

#endif
